import request from '@/utils/request'
import Qs from 'qs'

/** 租售订单列表 */
export const orderList = data => {
  return request({
    url: '/order/rentOrderList',
    method: 'post',
    data: Qs.stringify(data)
  })
}

/** 变更医生*/
export const distributeDoctor = data => {
  return request({
    url: '/serice_order/distributeDoctor',
    method: 'post',
    data
  })
}

/** 完成订单*/
export const finishOrder = data => {
  return request({
    url: '/serice_order/finishOrder',
    method: 'post',
    data
  })
}

/** 取消在线服务订单*/
export const cancleServiceOrder = data => {
  return request({
    url: '/serice_order/cancleServiceOrder',
    method: 'post',
    data
  })
}

/** 在线服务订单列表 */
export const onlineOrderList = data => {
  return request({
    url: '/serice_order/onlineOrderList',
    method: 'post',
    data
  })
}

/** 在线服务订单详情加载 */
export function onlineOrderDetail(query) {
  return request({
    url: '/serice_order/serviceOrderDetail',
    method: 'get',
    params: query,
    paramsSerializer: function(params) {
      return Qs.stringify(params, { arrayFormat: 'repeat' })
    }
  })
}

export function listOrder(query) {
  return request({
    url: '/order/list',
    method: 'get',
    params: query,
    paramsSerializer: function(params) {
      return Qs.stringify(params, { arrayFormat: 'repeat' })
    }
  })
}

export function detailOrder(id) {
  return request({
    url: '/order/detail',
    method: 'get',
    params: { id }
  })
}

export function shipOrder(data) {
  return request({
    url: '/order/ship',
    method: 'post',
    data
  })
}

export function refundOrder(data) {
  return request({
    url: '/order/refund',
    method: 'post',
    data
  })
}

export function payOrder(data) {
  return request({
    url: '/order/pay',
    method: 'post',
    data
  })
}

export function deleteOrder(data) {
  return request({
    url: '/order/delete',
    method: 'post',
    data
  })
}

export function replyComment(data) {
  return request({
    url: '/order/reply',
    method: 'post',
    data
  })
}

export function listChannel(id) {
  return request({
    url: '/order/channel',
    method: 'get'
  })
}

/** 取消租售订单*/
export const cancelOrder = data => {
  return request({
    url: '/order/cancelOrder',
    method: 'post',
    params: data
  })
}

/** 确认租售订单*/
export const confirmOrder = data => {
  return request({
    url: '/order/notTakingByself/taked',
    method: 'post',
    params: data
  })
}

/** 提交订单设置*/
export const orderSetting = data => {
  return request({
    url: '/order/orderSetting',
    method: 'get',
    params: data
  })
}
/** 获取订单设置*/
export const getOrderSetting = data => {
  return request({
    url: '/order/getOrderSetting',
    method: 'get',
    params: data
  })
}

/** 包裹打包*/
export const sureDelivery = data => {
  return request({
    url: '/order/notDeliver/sureDelivery',
    method: 'post',
    params: data
  })
}

/** 加载包裹*/
export const loadPack = query => {
  return request({
    url: '/order/notDeliver/load',
    method: 'get',
    params: query
  })
}

/** 取消包裹*/
export const cancelPack = data => {
  return request({
    url: '/order/cancelPack',
    method: 'post',
    params: data
  })
}

/** 点击同意、修改、修改金额*/
export const afterSaleButton = data => {
  return request({
    url: '/order/afterSale/button',
    method: 'post',
    data
  })
}

/** 售后订单列表*/
export const afterSaleList = data => {
  return request({
    url: '/order/afterSale/orderList',
    method: 'post',
    params: data
  })
}

/** 售后订单提交备注列表*/
export const postRemark = data => {
  return request({
    url: '/order/afterSale/remark',
    method: 'post',
    params: data
  })
}

/** 售后订单确认收货*/
export const receivedCommodity = data => {
  return request({
    url: '/order/afterSale/receivedCommodity',
    method: 'post',
    params: data
  })
}

/** 待用户自提状态下的订单点击取货*/
export const loadNotTakingByself = data => {
  return request({
    url: '/order/notTakingByself/load',
    method: 'post',
    params: data
  })
}

/** 待用户自提状态下的订单点击取货*/
export const packByself = data => {
  return request({
    url: '/order/notDeliver/packBySelf',
    method: 'post',
    params: data
  })
}

/** 待取货状态下的订单点击取货*/
export const loadNotPickUp = data => {
  return request({
    url: '/order/notPickUp/load',
    method: 'post',
    params: data
  })
}

/** 待用户自提-确认已收货 订单商品状态变更（租赁为使用者/售卖为已完成）*/
export const takeByself = data => {
  return request({
    url: '/order/notTakingByself/taked',
    method: 'post',
    params: data
  })
}

/** 待取货-取货 订单商品状态变更（商品状态变更为待商户收货）*/
export const postPickUp = data => {
  return request({
    url: '/order/notPickUp/pickUp',
    method: 'post',
    params: data
  })
}

/** 待收货状态下的订单点击退货/退款 */
export const refundLoad = data => {
  return request({
    url: '/order/notTake/returnLoad',
    method: 'post',
    params: data
  })
}

/** 待收货-退货/退款/换货 订单商品状态变更（退货、退款确认后商品状态变更为售后的待商户处理）*/
export const postReturn = data => {
  return request({
    url: '/order/notTake/return',
    method: 'post',
    data
  })
}

/** 使用中状态下的订单点击归还*/
export const getUsingReturn = data => {
  return request({
    url: '/order/returnCompleteEvent/' + data,
    method: 'post'
  })
}

/** 使用中-归还 订单商品状态变更（选择物流公司商品状态变更为待商户收货，选择门店商品状态变更为待取货）*/
export const postUsingReturn = data => {
  return request({
    url: '/order/using/return',
    method: 'post',
    params: data
  })
}

/** 使用中-归还 订单商品状态变更（选择物流公司商品状态变更为待商户收货，选择门店商品状态变更为待取货）*/
export const getUsingBuyOut = data => {
  return request({
    url: '/order/using/buyOutLoad',
    method: 'get',
    params: data
  })
}

/** 使用中-买断 订单商品状态变更（商品类型变更为出售，若租赁押金金额足够，则扣除押金中的商品金额，归还剩余押金金额，若押金金额不够，则扣除押金，订单商品转化为待用户结算）*/
export const postUsingBuyOut = data => {
  return request({
    url: '/order/using/buyOut',
    method: 'post',
    params: data
  })
}

/** 待商户收货-取货 订单商品状态变更（若客户付款金额足够，商品状态变更为已完成，若客户金额不足，商品状态变更为待客户结算）*/
export const postTakingByBusiness = data => {
  return request({
    url: '/order/notTakingByBusiness/take',
    method: 'post',
    params: data
  })
}

/**
 * 根据不同的订单状态加载订单详情页
 * // /order/rentOrderDetail
 */
export const rentOrderDetail = data => {
  return request({
    url: '/order/rentOrderDetail',
    method: 'post',
    data: Qs.stringify(data)
  })
}
/**
 * 待发货状态下的订单点击去发货或者待发货状态下修改包裹信息
 */
export const notDeliver = data => {
  return request({
    url: '/order/notDeliver/load',
    method: 'post',
    data: Qs.stringify(data)
  })
}
/**
 * 待付款点击改价获取子订单以及商品详情
 */
export const getUpdatePrice = data => {
  return request({
    url: '/order/getSubOrderAndGoodsInformation',
    method: 'post',
    data: Qs.stringify(data)
  })
}
/**
 * 待付款点击改价获取子订单以及商品详情
 */
export const updatePriceAndFreight = data => {
  return request({
    url: '/order/updatePriceAndFreight',
    method: 'post',
    data
  })
}

/**
 * 使用中状态下的订单点击买断
 */
export const buyOutLoad = data => {
  return request({
    url: '/order/using/buyOutLoad',
    method: 'post',
    params: data
  })
}

/**
 * 使用中-买断 订单商品状态变更（商品类型变更为出售，若租赁押金金额足够，则扣除押金中的商品金额，归还剩余押金金额，若押金金额不够，则扣除押金，订单商品转化为待用户结算）
 */
export const postBuyout = data => {
  return request({
    url: '/order/using/buyOut',
    method: 'post',
    data
  })
}

/**
 * 使用中状态下的订单点击归还
 */
export const rebackLoad = id => {
  return request({
    url: '/order/returnCompleteEvent/' + id,
    method: 'post'
  })
}

/**
 * 使用中-买断 订单商品状态变更（商品类型变更为出售，若租赁押金金额足够，则扣除押金中的商品金额，归还剩余押金金额，若押金金额不够，则扣除押金，订单商品转化为待用户结算）
 */
export const postReback = data => {
  return request({
    url: '/order/using/return',
    method: 'post',
    params: data
  })
}

/**
 * 根据不同的售后订单状态加载订单详情页
 * */
export const afterSaleDetail = data => {
  return request({
    url: '/order/afterSale/orderDetail',
    method: 'post',
    params: data
  })
}

/**
 * 手动更新子订单的状态
 * */
export const updateChildOrderStatus = data => {
  return request({
    url: '/order/updateChildOrderStatus',
    method: 'post',
    params: data
  })
}

/**
 * 手动更新子订单的状态
 * */
export const confirmReceiptNormal = data => {
  return request({
    url: '/order/confirmReceiptNormal',
    method: 'post',
    params: data
  })
}
